<template>
  <div class="orderDetail-box">
    <div class="header">
      <h5>处理售后单</h5>
      <i class="iconfont icon-close" @click="close"></i>
    </div>
    <el-form class="form-box" :model="ruleForm" ref="ruleFormRef" :rules="rules">
      <el-form-item prop="aftersaleCost" label="售后总金额">
        <label>
          <el-input v-model="ruleForm.aftersaleCost" placeholder="售后总金额" />
        </label>
      </el-form-item>
      <el-form-item prop="aftersalesuccessPhoto"  label="上传售后完成图">
        <label>
            <div class="upload">
              <ImageUpload
                :limit="6"
                :isShowTip="false"
                @update:modelValue="handlerModelValue"
                :fileType="fileType"
                :modelValue="dialogImageUrl"
              />
              <el-dialog v-model="dialogVisible">
                <img w-full :src="dialogImageUrl" alt="Preview Image" />
              </el-dialog>
            </div>
        </label>
      </el-form-item>

      <el-form-item class="btn-box">
        <el-button @click="resetForm(ruleFormRef)" style="background: #f2f3f5">重置</el-button>
        <el-button type="primary" @click.stop="submitForm(ruleFormRef)"> 提交 </el-button>
      </el-form-item>
    </el-form>


  </div>
</template>
<script setup>
import { reactive, ref, defineEmits, defineProps } from 'vue'
import ImageUpload from '@/components/ImageUpload/index.vue'
import { insertAfterSaleOrderApi, updateAfterSaleAPi } from '@/api/teams/index.js'
const { proxy } = getCurrentInstance();



const emit = defineEmits(['closePopUps'])
const dialogVisible = ref(false)
const dialogImageUrl = ref('')
const ruleFormRef = ref(null)
const rules = reactive({
  aftersaleCost: [{ required: true, message: '请填写售后详情', trigger: 'blur' }],
  aftersalesuccessPhoto: [{ required: true, message: '请上传售后完成图”', trigger: 'change' }],
})
// 图片类型
let fileType = ['png', 'jpg', 'jpeg', 'jfif']
const ruleForm = reactive({
  aftersaleCost: '',
  aftersalesuccessPhoto: [],
})
const props = defineProps({
  // 订单详情信息
  rowDataDetail: {
    type: Object,
    default: [],
    required: true,
  },
  widthMy: {
    type: String,
  }, id: {
    type: String,
  },
})

// 关闭当前框
const close = () => {
  emit('closePopUps', false)
}
// 获取的图片
const handlerModelValue = async (v) => {
  ruleForm.aftersalesuccessPhoto = v
}
const submitForm = async (formEl) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      let params = {
        aftersalesuccessPhoto: JSON.stringify(ruleForm.aftersalesuccessPhoto),
        aftersaleCost: ruleForm.aftersaleCost,
        id:props.id,
        successTime:new Date(),
        type:'已完成'
      }
      updateAfterSaleAPi(params).then(res => {
        if(res.code === 200) {
          proxy.$modal.msgSuccess(res.msg);
          emit('closePopUps', false)
        }
      })
    } else {
      console.log('提交失败', fields)
    }
  })
}
// 重置
const resetForm = (formEl) => {
  if (!formEl) return
  formEl.resetFields()
}








</script>
<style scoped lang="scss">
.optionsOrder {
  padding: 20px 20px 0 20px;
  height: 100%;

  header {
    margin-bottom: 20px;
    font-weight: 550;
  }



  .btnSub {
    width: 100%;
    text-align: right;
    margin-top: 30px;

    .el-button {
      width: 50px;
      height: 25px;
      font-size: 12px;
    }
  }
}

.orderDetail-box {
  width: 100%;
  height: 100%;
  overflow-y: scroll;

  .未完成 {
    color: red;
  }

  .已支付 {
    color: green;
  }

  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #1947ff;
    border-radius: 4px 4px 0px 0px;
    padding: 0 30px;
    height: 40px;
    width: 100%;

    h5 {
      color: #fff;
      font-weight: 600;
    }

    .icon-close {
      border: 1px solid #666;
      color: #1947ff;
      background: #ffffff;
    }
  }
  .form-box{
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100% !important;
    align-items: center;
  }
  .content {
    padding-top: 40px;
    color: #333333;

    .content-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 10px;
    }

    .content-main {
      padding: 0 20px;
      display: flex;
      align-items: center;
      flex-wrap: wrap;

      .list-left,
      .list-right {
        display: flex;
        align-items: center;
        width: 33.33%;

        p {
          height: 40px;
          line-height: 40px;
        }
      }

      .desc-list {
        display: flex;
        align-items: center;
        width: 100%;

        .desc-right {
          margin: 5px 0;

          .el-textarea {
            width: 800px;
          }
        }
      }
    }

    .content-bottom {
      padding: 0 20px;
      display: flex;
      justify-content: space-between;

      .bottom-left {
        margin-top: 10px;
        display: flex;

        p {
          color: #1947ff;
        }
      }

      .bottom-right {
        margin: 40px 0;

        p {
          width: 58px;
          height: 28px;
          background: linear-gradient(180deg, #d8e0ff 0%, #ffffff 100%);
          box-shadow: 2px 3px 6px 1px rgba(0, 0, 0, 0.16);
          border-radius: 2px 2px 2px 2px;
          text-align: center;
          line-height: 28px;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
